package com.example.ycq;

import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.PlatformTransactionManager;

import javax.annotation.PostConstruct;

@SpringBootApplication( scanBasePackages = "com.example.ycq")
@MapperScan(basePackages="com.example.ycq",annotationClass=Repository.class)//annotationClass:注释类
public class MybatisJdbcApplication {

    //注入RedisTemplate
    @Autowired
    private RedisTemplate redisTemplate=null;

    //定义自定义后初始化方法
    @PostConstruct
    public void init(){
        initRedisTemplate();
    }

    //设置RedisTemplate的序列化器
    private void initRedisTemplate(){
        RedisSerializer stringSerializer=redisTemplate.getStringSerializer();
        redisTemplate.setKeySerializer(stringSerializer);
        redisTemplate.setHashKeySerializer(stringSerializer);
        redisTemplate.setValueSerializer(stringSerializer);
        redisTemplate.setHashValueSerializer(stringSerializer);
    }

    public static void main(String[] args) {
        SpringApplication.run(MybatisJdbcApplication.class, args);
    }


    //注入事务管理器，它由springboot自动生成
    @Autowired
    private PlatformTransactionManager transactionManager=null;

    //使用后初始化方法，观察自动生成的事务管理器
    @PostConstruct //类对象被初始化后会调用这个方法
    public void viewTransactionManager(){
        //启动前加入断点观测
        System.out.println(transactionManager.getClass().getName());
    }


}
